--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit bd56b884ba24098a7d7158f5e442eac4c9bff7ec
Parents : c77629d
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-04-13T18:26:53-05:00
feat(electron): add file and directory selection dialogs; implement open path functionality
Changes
3 files changed, 95 insertions(+), 0 deletions(-)
Diff
diff --git a/electron/main-legacy.js b/electron/main-legacy.js
index 86d44e76..af61fe2c 100644
--- a/electron/main-legacy.js
+++ b/electron/main-legacy.js
@@ -17,6 +17,17 @@ const crypto = require("crypto");
// remember main window
var mainWindow = null;
+function getDialogParentWindow() {
+ const focused = BrowserWindow.getFocusedWindow();
+ if (focused && !focused.isDestroyed()) {
+ return focused;
+ }
+ if (mainWindow && !mainWindow.isDestroyed()) {
+ return mainWindow;
+ }
+ return null;
+}
+
// power save blocker id
var activePowerSaveBlockerId = null;
@@ -190,6 +201,38 @@ ipcMain.handle("showPathInFolder", (event, path) => {
shell.showItemInFolder(path);
});
+ipcMain.handle("open-path", (event, p) => {
+ return shell.openPath(p);
+});
+
+ipcMain.handle("pick-file", async () => {
+ const win = getDialogParentWindow();
+ if (!win) {
+ return null;
+ }
+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {
+ properties: ["openFile"],
+ });
+ if (canceled || !filePaths || filePaths.length === 0) {
+ return null;
+ }
+ return filePaths[0];
+});
+
+ipcMain.handle("pick-directory", async () => {
+ const win = getDialogParentWindow();
+ if (!win) {
+ return null;
+ }
+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {
+ properties: ["openDirectory"],
+ });
+ if (canceled || !filePaths || filePaths.length === 0) {
+ return null;
+ }
+ return filePaths[0];
+});
+
function log(message) {
// log to stdout of this process
console.log(message);
diff --git a/electron/main.js b/electron/main.js
index 576b4967..9543ed34 100644
--- a/electron/main.js
+++ b/electron/main.js
@@ -21,6 +21,17 @@ const crypto = require("crypto");
// remember main window
var mainWindow = null;
+function getDialogParentWindow() {
+ const focused = BrowserWindow.getFocusedWindow();
+ if (focused && !focused.isDestroyed()) {
+ return focused;
+ }
+ if (mainWindow && !mainWindow.isDestroyed()) {
+ return mainWindow;
+ }
+ return null;
+}
+
// tray instance
var tray = null;
@@ -265,6 +276,38 @@ ipcMain.handle("showPathInFolder", (event, path) => {
shell.showItemInFolder(path);
});
+ipcMain.handle("open-path", (event, p) => {
+ return shell.openPath(p);
+});
+
+ipcMain.handle("pick-file", async () => {
+ const win = getDialogParentWindow();
+ if (!win) {
+ return null;
+ }
+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {
+ properties: ["openFile"],
+ });
+ if (canceled || !filePaths || filePaths.length === 0) {
+ return null;
+ }
+ return filePaths[0];
+});
+
+ipcMain.handle("pick-directory", async () => {
+ const win = getDialogParentWindow();
+ if (!win) {
+ return null;
+ }
+ const { canceled, filePaths } = await dialog.showOpenDialog(win, {
+ properties: ["openDirectory"],
+ });
+ if (canceled || !filePaths || filePaths.length === 0) {
+ return null;
+ }
+ return filePaths[0];
+});
+
function log(message) {
// log to stdout of this process
console.log(message);
diff --git a/electron/preload.js b/electron/preload.js
index 8846598a..19dc2e28 100644
--- a/electron/preload.js
+++ b/electron/preload.js
@@ -63,6 +63,15 @@ contextBridge.exposeInMainWorld("electron", {
showPathInFolder: async function (path) {
return await ipcRenderer.invoke("showPathInFolder", path);
},
+ openPath: async function (path) {
+ return await ipcRenderer.invoke("open-path", path);
+ },
+ pickFile: async function () {
+ return await ipcRenderer.invoke("pick-file");
+ },
+ pickDirectory: async function () {
+ return await ipcRenderer.invoke("pick-directory");
+ },
// allow checking hardware acceleration status
isHardwareAccelerationEnabled: async function () {
return await ipcRenderer.invoke("is-hardware-acceleration-enabled");
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────